using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using BA.DAL;

namespace BlazeApps.Library.Blog
{
    public class BlogList : Base
    {
        private BA.DAL.DBUtility DAL = new BA.DAL.DBUtility();
        private Procedures Procs = new Procedures();

        public DataTable GetBlogs()
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            return DAL.GetDataTable(Procs.ListBlogs.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetBlogs(Guid UserID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@userid", UserID);

            return DAL.GetDataTable(Procs.ListBlogsByUser.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetBlogs(DateTime Date)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@date", Date);

            return DAL.GetDataTable(Procs.ListBlogsByDate.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetBlogs(int Month, int Year)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@month", Month);
            DAL.AddParameter("@year", Year);

            return DAL.GetDataTable(Procs.ListBlogsByMonthYear.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetBlogs(Guid UserID, int Month, int Year, BlogType Type)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);
            string Procedure = string.Empty;

            DAL.AddParameter("@userid", UserID);
            DAL.AddParameter("@month", Month);
            DAL.AddParameter("@year", Year);

            if (Type == BlogType.BlogsByUser)
            {
                Procedure = Procs.ListBlogsByUserMonthYear.ToString().Trim();
            }

            if (Type == BlogType.MyBlogs)
            {
                Procedure = Procs.ListMyBlogs.ToString().Trim();
            }

            return DAL.GetDataTable(Procedure, System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetBlogPeriods()
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            return DAL.GetDataTable(Procs.ListBlogsPeriodCount.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetBlogPeriods(Guid UserID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@userid", UserID);

            return DAL.GetDataTable(Procs.ListBlogsPeriodCountByUser.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable SearchBlogs()
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            return DAL.GetDataTable(Procs.SearchAllBlogs.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable SearchBlogs(Guid UserID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@userid", UserID);

            return DAL.GetDataTable(Procs.SearchBlogsByUser.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }
    }
}
